<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>JavaScript第十六课</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script src="js/js.js"></script>
    <style>
        div li {
            background-color: red;
        }

        div>font {
            font-size: 180px;
            color: blue;
        }
    </style>
</head>

<body>

    <form id="test-form" action="#0" onsubmit="return chec();">
        <p><label>Name: <input name="name" value="这是一个默认值,你不能指望它"></label></p>
        <p><label>Email: <input name="email"></label></p>
        <p><label>Password: <input name="password" type="password"></label></p>
        <p>Gender: <label><input name="gender" type="radio" value="m" checked> Male</label> <label><input name="gender"
                    type="radio" value="f"> Female</label></p>
        <p><label>City: <select name="city" multiple>
                    <option value="BJ" selected>Beijing</option>
                    <option value="SH">Shanghai</option>
                    <option value="CD">Chengdu</option>
                    <option value="XM">Xiamen</option>
                </select></label></p>
        <p><button type="submit">Submit</button></p>
    </form>


</body>
<script>
    function chec(){
        var name=$('option:selected').map((index,item)=>{
            console.log(index);
            console.log(item.value);
            return item.value;
        });
        console.log(name);

        var json={
            city:name
        }
        console.log(JSON.stringify(json));

        return false;
    }
    

    // var json={
    //     name:name   
    // }

    // console.log(JSON.stringify(json));
</script>

</html>